package _021_10_8

import (
	"math"
	"strconv"
)

/**
 *
 * @param x int整型
 * @return int整型
 */
func reverse(x int) int {
	num := strconv.Itoa(x)
	t := 0
	if x < 0 {
		t = 1
	}
	data := make([]byte, len(num)-t)

	for i := 0; i < len(data); i++ {
		data[i] = num[i+t]
	}
	for i := 0; i < len(data)/2; i++ {
		temp := data[i]
		data[i] = data[len(data)-i-1]
		data[len(data)-1-i] = temp
	}
	result := ""
	for i := 0; i < len(data); i++ {
		result += string(data[i])
	}
	atoi, _ := strconv.Atoi(result)
	if atoi > math.MaxInt32 {
		atoi = 0
	}
	if x < 0 {
		atoi = -atoi
	}
	return atoi
}
